package com.tlgen.tomcat.controller;

import com.google.common.collect.Lists;
import com.tlgen.tomcat.annotation.*;
import com.tlgen.tomcat.common.R;
import com.tlgen.tomcat.model.SysUser;
import com.tlgen.tomcat.service.SysUserService;

import java.util.Collection;
import java.util.List;
import java.util.Map;

@RequestMapping("/user")
public class SysUserController {

    @GetMapping("/selectList")
    public Object selectList(String username, String mobile, int status, boolean flag) {
        SysUserService sysUserService = () -> {
            List<SysUser> userList = Lists.newArrayList();
            SysUser user1 = SysUser.builder().username("11").mobile("136xx").email("11@qq.com").build();
            SysUser user2 = SysUser.builder().username("22").mobile("136xx").email("22@qq.com").build();
            SysUser user3 = SysUser.builder().username("33").mobile("136xx").email("33@qq.com").build();
            userList.add(user1);
            userList.add(user2);
            userList.add(user3);
            return userList;
        };
        List<SysUser> userList = sysUserService.selectList();
        return R.ok(userList, "查询用户数据列表成功!");
    }

    @GetMapping("/select/{username}/{mobile}")
    public Object select(@PathVariable("username") String username, @PathVariable("mobile") String mobile) {
        return R.ok("查询成功!");
    }

    @PostMapping("/save")
    public Object save(@RequestBody SysUser user) {
        return R.ok("保存用户数据成功!");
    }

    @PostMapping("/saveBatch")
    public Object saveBatch(@RequestParam("username") String username,
                            @RequestParam("email") String email,
                            @RequestParam("status") Integer status) {
        return R.ok("批量保存用户数据成功!");
    }

    @PostMapping("/saveUser/{username}/{email}")
    public Object saveUser(@PathVariable("username") String username, @PathVariable("email") String email) {
        return R.ok("saveUser 保存用户数据成功!");
    }

    @PostMapping("/saveUserByMap")
    public Object saveUserByMap(@RequestBody Map<String, Object> map) {
        System.out.println(map);
        return "saveUserByMap 保存用户数据成功!";
    }

    @PostMapping("/saveUserByList")
    public Object saveUserByList(@RequestBody List<SysUser> userList) {
        System.out.println(userList);
        return "saveUserByList 保存用户数据成功!";
    }

    @PostMapping("/saveUserByCollection")
    public Object saveUserByCollection(@RequestBody Collection<SysUser> userList) {
        System.out.println(userList);
        return "saveUserByCollection 保存用户数据成功!";
    }

    @PostMapping("/saveUserByObject")
    public Object saveUserByObject(@RequestBody Object object) {
        System.out.println(object);
        return "saveUserByObject 保存用户数据成功!";
    }

    @PutMapping("/update")
    public Object update(@RequestBody SysUser user) {
        return R.ok("更新用户数据成功!");
    }

    @PutMapping("/updateBatch")
    public Object updateBatch(@RequestParam("username") String username, @RequestParam("email") String email) {
        return R.ok("批量更新用户数据成功!");
    }

    @PutMapping("/updateUser/{username}/{email}")
    public Object updateUser(@PathVariable("username") String username, @PathVariable("email") String email) {
        return R.ok("updateUser 更新用户数据成功!");
    }

    @PutMapping("/updateUserByMap")
    public Object updateUserByMap(@RequestBody Map<String, Object> map) {
        System.out.println(map);
        return "updateUserByMap 更新用户数据成功!";
    }

    @DeleteMapping("/delete/{username}/{mobile}")
    public Object delete(@PathVariable("username") String username, @PathVariable("mobile") String mobile) {
        return R.ok("删除成功!");
    }

    @DeleteMapping("/deleteBatch")
    public Object deleteBatch(@RequestBody SysUser user) {
        return R.ok("批量删除成功!");
    }

    @DeleteMapping("/deleteBatch2")
    public Object deleteBatch2(@RequestParam("username") String username, @RequestParam("email") String email) {
        return R.ok("批量删除成功2!");
    }

    @DeleteMapping("/deleteUserByMap")
    public Object deleteUserByMap(@RequestBody Map<String, Object> map) {
        System.out.println(map);
        return "deleteUserByMap 删除用户数据成功!";
    }

}
